<!DOCTYPE html>
<html>
  <head>
    <title>文件上传下载浏览器</title>
    <link rel='stylesheet' href='style.css' />
  </head>
  <body>
    <h2>文件上传下载浏览器</h2>
    <div class="caption">
      <div class="now">
        <%= dir %>
      </div>
      <div class="up" style="display: none;">
        <form action="/u" method="POST" enctype="multipart/form-data">
          <input type="file" name="file" style="width: 200px;" onchange="document.forms[0].submit();" required />
        </form>
      </div>
    </div>
  	<table border="0" cellpadding="0" cellspacing="0">
      <tr>
      	<th width="30px"></th>
        <th width="auto">名称</th>
        <th width="200px">大小</th>
        <th width="150px">类型</th>
        <th width="250px">修改时间</th>
      </tr>
      <tr>
        <td></td>
        <td colspan="4">
          <a href="<%= father %>">【上一级】</a>
          <a href="javascript:newDir()">【新建文件夹】</a>
          <a href="javascript:upload()">【上传文件】</a>
        </td>
      </tr>
  		<% for(i in childs) { %>
  		<tr>
  			<td><%- (childs[i].href.toLowerCase().endsWith('.jpg') || childs[i].href.toLowerCase().endsWith('.png'))?'<button class="tou" onclick="preview(\''+ childs[i].href +'\')">看</button>':'' %></td>
  			<td><a href="<%= childs[i].href %>" <%- childs[i].type=='文件'?'target="_blank"':'' %>><%= childs[i].name %></a></td>
  			<td align="right"><span><%= childs[i].size %></span></td>
        	<td align="center"><%= childs[i].type %></td>
        	<td align="center"><%= childs[i].mtime %></td>
  		</tr>
  		<% } %>
  	</table>
  	<div id="preview" title="隐藏" onclick="hideview()"></div>
    <script type="text/javascript">
      //window.history.replaceState && window.history.replaceState({ title: '', url: '/' }, '', '/');
      var view = document.getElementById('preview');
      function preview(src) {
      	view.style.display = 'block';
      	view.style.backgroundImage = "url('" + src + "')";
      }
      function hideview() {
      	view.style.display = 'none';
      	view.style.backgroundImage = "";
      }
      function newDir() {
        var d = prompt("输入文件夹名称：","新建文件夹");
        if (d) {
          location.href = 'c?d=' + d;
        }
      }
      function upload() {
        document.forms[0].file.click();
      }
    </script>
  </body>
</html>
